#!/bin/bash
export ANDROID_NDK_ROOT=/mnt/android_home/ndk/android-ndk-r28c
# 例如：
# 清理旧构建
rm -rf $BUILD_DIR $INSTALL_DIR

SYSTEMROOT=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot
TOOLCHAIN_PREFIX=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64
API=21
#cd /opt/module/ffmpeg/src/release/4.4 ll -l /mnt/android_home/ndk/android-ndk-r28ctoolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/pkgconfig
cd /opt/module/src/ffmpeg/n8.0
CPU=armv8-a
PREFIX=$PWDPATH/android/lib/$CPU
ARCH=arm64
CFLAGS="-march=armv8-a"
ARCH_TYPE=aarch64-linux-android
CXX=$TOOLCHAIN_PREFIX/bin/$ARCH_TYPE$API-clang++
CC=$TOOLCHAIN_PREFIX/bin/$ARCH_TYPE$API-clang
# 指向你为 Android 编译的库的 pkgconfig 目录
export OPENSSL_PKG_CONFIG=/opt/android/module/install/openssl/openssl-3.0.15/android/arm64-v8a/21/lib/pkgconfig
export X264_PKG_CONFIG=/opt/android/module/install/x264/android/arm64-v8a/21/lib/pkgconfig
# 其他库同理...

# 设置 PKG_CONFIG_PATH
export PKG_CONFIG_PATH="$OPENSSL_PKG_CONFIG:$X264_PKG_CONFIG"

# 设置 pkg-config 为静态链接模式（重要！避免引入主机库）
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_PATH
export PKG_CONFIG_SYSROOT_DIR=/
./configure \
--prefix=$PREFIX \
--arch=$ARCH \
--target-os=linux \
--enable-cross-compile \
--cross-prefix=$TOOLCHAIN_PREFIX/bin/llvm- \
--sysroot=$SYSTEMROOT \
--cxx=$CXX \
--cc=$CC \
--nm=$TOOLCHAIN_PREFIX/bin/llvm-nm \
--extra-cxxflags="-D__thumb__ -fexceptions -frtti" \
--extra-cflags="$CFLAGS -Os -fPIC -DANDROID -Wfatal-errors -Wno-deprecated -I/opt/android/module/prefix/android/arm64-v8a/21/include" \
--extra-ldflags="-L$SYSTEMROOT/usr/lib -L/opt/android/module/prefix/android/arm64-v8a/21/lib" \
--disable-shared \
--enable-static \
--enable-gpl \
--pkg-config=pkg-config \
--pkg-config-flags="--static" \
--enable-version3 \
--enable-openssl

